var paytype=0;

$(document).ready(function(){
	
	choosePayT();
	payM();
	checkS();
	WantOrderDetail();
	GotoRepay();
});

//选择付款方式绑定事件
function choosePayT(){
	$("div.rentpay_info_down_down_weixin").click(function(){
		$("img.rentpay_info_down_down_weixin_twoposi").removeClass("hidden");
		$("img.rentpay_info_down_down_zhifubao_twoposi").addClass("hidden");
		$("div.rentpay_info_down_down_weixin").addClass("errorb");
		$("div.rentpay_info_down_down_zhifubao").removeClass("errorb");
		paytype=0;//paytype==0为微信支付
	});
	$("div.rentpay_info_down_down_zhifubao").click(function(){
		$("img.rentpay_info_down_down_zhifubao_twoposi").removeClass("hidden");
		$("img.rentpay_info_down_down_weixin_twoposi").addClass("hidden");
		$("div.rentpay_info_down_down_weixin").removeClass("errorb");
		$("div.rentpay_info_down_down_zhifubao").addClass("errorb");//不知道为何变色未启动
		paytype=1;//paytype==1为支付宝支付
	});
}
//付款跳转绑定
function payM(){
	$("input.linepay_info_pay_b").click(function(){
		
		if(paytype == 0){
			$('div#myModal').modal("show")
			window.open(basePath+"/rentweixinpay");
			console.log("微信付款");
		};
		if(paytype == 1){
			$('div#myModal').modal("show")
			window.open(basePath+"/pay/alipay/alipay");
			console.log("支付宝付款");
		}
	});	
}
//支付成功按钮绑定判定事件
function checkS(){
	$("button.btn-default:eq(0)").click(function(){
		wantS();
		console.log("click");
	});
}
//判定是否支付成功
function wantS(){
	var orderid=$("div.rentpay_orderinfo>div:eq(0)").text();
		$.ajax({	
			dataType : "json",
			type : "post",
			url : basePath+"/car/orderstate",
			data : {
				orderid:orderid
			},
			
			contentType : "application/x-www-form-urlencoded;charset=utf-8",
			success : function(data) {
				if(data.data.state=="success"){
					$("div#myModal").modal("hide");
					$("div#myModal1").modal("show");
				}else{
					$("div#myModal").modal("hide");
					$("div#myModal2").modal("show");
				}		
			},
			error : function() {
				console.log("访问失败");
			},
			complete : function() {
				
			},
		});
}
//请求支付页面详情信息
function WantOrderDetail(){
	var orderid = $("div.rentpay_orderinfo>div").text();
	$.ajax({	
		dataType : "json",
		type : "post",
		url : basePath+"/line/linepayalldetailinfo",
		data : {
			orderid:orderid
		},
		
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(data) {
			var title = data.data.title;
			var num = data.data.ordernum;
			var price = data.data.price;
			var	car = data.data.car;
			var city = data.data.city;
			var begintime = data.data.begindate;
			var adultnum = data.data.adultnum;
			var kidsnum = data.data.kidsnum;
			var picture = data.data.picture;
			var cname = data.data.cname;
			var phone = data.data.phone;
			var email = data.data.email;			
			$("div.linepay_info_top_info_center_two").text(title);
			$("div.linepay_info_top_info_down_two").text(num);
			$("div.linepay_info_top_price_three").text(price);
			$("div.linepay_info_center_up_two_title").text(car);
			$("div.linepay_info_center_up_two_start_time").text(city);
			$("div.linepay_info_center_up_two_end_time:eq(0)").text(begintime);
			$("div.linepay_info_center_up_two_end_time:eq(1)").text(adultnum);
			$("div.linepay_info_center_up_two_end_city:eq(1)").text(kidsnum);
			$("img.linepay_info_center_up_one_posi").attr("src",picture);
			$("div.rentpay_info_center_down_item_two:eq(0)").text(cname);
			$("div.rentpay_info_center_down_item_two:eq(1)").text(phone);
			$("div.rentpay_info_center_down_item_two:eq(2)").text(email);
			
			var a = "";
			var k = "";
			for(var i =0;i<data.data.adult.length;i++){
				a = a +  "<div class=\"linepay_info_center_down_adult_item row\">\n" +
				"<div class=\"col-md-3 col-lg-3\"></div>\n" +
				"<div class=\"col-md-2 col-lg-2 linepay_info_center_down_adult_item_left\">\n" +
				"<div class=\"linepay_info_center_down_adult_item_left_up\">第"+(i+1)+"位</div>\n" +
				"<div class=\"linepay_info_center_down_adult_item_left_down\">成人</div>\n" +
				"</div>\n" +
				"<div class=\"col-md-4 col-lg-4 linepay_info_center_down_adult_item_right\">\n" +
				"<div class=\"linepay_info_center_down_adult_item_right_item clearfix\">\n" +
				"<div class=\"linepay_info_center_down_adult_item_right_item_name\">姓名：</div>\n" +
				"<div class=\"linepay_info_center_down_adult_item_right_item_content\">"+data.data.adult[i].name+"</div>\n" +
				"</div>\n" +
				"<div class=\"linepay_info_center_down_adult_item_right_item clearfix\">\n" +
				"<div class=\"linepay_info_center_down_adult_item_right_item_name\">证件号码：</div>\n" +
				"<div class=\"linepay_info_center_down_adult_item_right_item_content\">"+data.data.adult[i].identnum+"</div>\n" +
				"</div>\n" +
				"<div class=\"linepay_info_center_down_adult_item_right_item clearfix\">\n" +
				"<div class=\"linepay_info_center_down_adult_item_right_item_name\">手机号码：</div>\n" +
				"<div class=\"linepay_info_center_down_adult_item_right_item_content\">"+data.data.adult[i].phone+"</div>\n" +
				"</div>\n" +
				"</div>\n" +
				"</div>";
			};
			for(var i =0;i<data.data.kids.length;i++){
				k = k +  "<div class=\"linepay_info_center_down_adult_item row\">\n" +
				"<div class=\"col-md-3 col-lg-3\"></div>\n" +
				"<div class=\"col-md-2 col-lg-2 linepay_info_center_down_adult_item_left\">\n" +
				"<div class=\"linepay_info_center_down_adult_item_left_up\">第"+(i+1)+"位</div>\n" +
				"<div class=\"linepay_info_center_down_adult_item_left_down\">儿童</div>\n" +
				"</div>\n" +
				"<div class=\"col-md-4 col-lg-4 linepay_info_center_down_adult_item_right\">\n" +
				"<div class=\"linepay_info_center_down_adult_item_right_item clearfix\">\n" +
				"<div class=\"linepay_info_center_down_adult_item_right_item_name\">姓名：</div>\n" +
				"<div class=\"linepay_info_center_down_adult_item_right_item_content\">"+data.data.kids[i].name+"</div>\n" +
				"</div>\n" +
				"<div class=\"linepay_info_center_down_adult_item_right_item clearfix\">\n" +
				"<div class=\"linepay_info_center_down_adult_item_right_item_name\">证件号码：</div>\n" +
				"<div class=\"linepay_info_center_down_adult_item_right_item_content\">"+data.data.kids[i].identnum+"</div>\n" +
				"</div>\n" +
				
				"</div>\n" +
				"</div>";
			};
			$("div.linepay_info_center_down_adult").html(a);
			$("div.linepay_info_center_down_kid").html(k);
			
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			layer.close(LoadingIcon);
		},
	});
}
//跳转订单支付详情页面
var GotoRepay = function(){
	var url = basePath+"/linerepay";
	url = encodeURI(url);
	url = encodeURI(url);
	//重点步骤，转码2次，实现传参不出中文乱码或问号
	
	$("button#CheckOrderTwo").click(function(){
		window.location.href = (url);
	});
	$("button#CheckOrderOne").click(function(){
		window.location.href = (url);
	});
	$("button.btn-default:eq(2)").click(function(){
		window.location.href = (url);
	});
}